# -*- coding: utf-8 -*-
#
#    Copyright (C) 2013 Gonzalo Bonigo <gonzalobonigo@gmail.com>
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see http://www.gnu.org/licenses/
#


"""Este archivo contiene la definicion de la clase Stack."""


__all__ = [
    "Stack"
]


class Stack(list):
    """This is a stack."""

    #
    # Atributos de clase privados.
    #
    _TOP = -1

    #
    # Metodos publicos.
    #

    def push(self, data):
        """Pone un elemento en el tope de la pila."""
        self.append(data)

    def pop(self):
        """Saca el elemento que esta al tope de la pila y lo devuelve.
           Si esta vacia devuelve None."""
        data = None
        if len(self) > 0:
            data = super(Stack, self).pop(Stack._TOP)
        return data

    def top(self):
        """Devuelve el tope de la pila. Si la pila esta vacia devuelve None."""
        data = None
        if len(self) > 0:
            data = self[Stack._TOP]
        return data
